const mongoose = require('mongoose');

function connectToDB() {
    mongoose.connect('mongodb://localhost:27017/test', {useNewUrlParser: true});

    /*const Cat = mongoose.model('Cat', { name: String });

    const kitty = new Cat({ name: 'Zildjian' });
    kitty.save().then(() => console.log('meow'));*/

    const db = mongoose.connection;
    db.on('error',err=>{
        console.log('connect db error: '+err);
    });

    db.once('open',()=>{
        console.log('db connect successfully') ;
    });
}

module.exports={connectToDB};